<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript">
$(document).ready(function(){
	$("#form").submit(function(){
		var formOptions={
		        beforeSubmit:  showRequest,  // pre-submit callback 
		        success:       showResponse,  // post-submit callback 
		        dataType:'json',
		        error:showError,
		        resetForm: true        // reset the form after successful submit 
		}
		$(this).ajaxSubmit(formOptions);
		return false;
	});
});

function showRequest(formData,jqForm,options){
	return true;
}

function showResponse(responseText,statusText,xhr,$form){
	if(responseText.success){
		showNoticeMessage("Upload File Success");
		console.info(responseText);
	}else{
		showErrorMessage("Upload Failed, Reason:"+responseText.error);
	}
}

function showError(xhr,textStatus,errorThrown){
	showErrorMessage("Upload Failed, Reason:"+errorThrown);
}
</script>
<title>File Upload</title>
</head>
<body>
	<div class="secondary-navigation">
		<ul class="wat-cf">
			<li class="first active"><a href="/admin/upload">Upload</a></li>
			<li><a href="/admin/upload/list">List</a> </li>
		</ul>
	</div>
	<div class="block" id="block-form">
		<div class="content">
			<div class="flash"></div>
			<div class="inner">
				<h2 class="title">File Upload</h2>
				<form:form enctype="multipart/form-data" id="form" action="/service/file_storage/insert" method="post" cssClass="form"
					modelAttribute="fileStorageModel">
					<div class="group">
						<form:label cssClass="label" for="file" path="file">File</form:label>
						<form:input cssClass="text_field" path="file" type="file" />
						<span class="description">Max file Size 1mB</span>
					</div>
					<div class="group">
						<form:label cssClass="label" for="codename" path="codename">Codename</form:label>
						<form:input cssClass="text_field" type="text" path="codename" />
						<span class="description">Tanpa Space</span>
					</div>
					<div class="group">
						<form:label cssClass="label" for="description" path="description">Description</form:label>
						<form:textarea cssClass="text_area" path="description" />
						<span class="description">Deskripsi untuk file</span>
					</div>
					<div class="group navform wat-cf">
						<button class="button" type="submit">
							<img src="/images/icons/tick.png" alt="Save"> Save
						</button>
						<button class="button" type="reset">Reset</button>
					</div>

				</form:form>
			</div>
		</div>
	</div>
</body>
</html>